package com.evil.kingdom.pojo.entity.base;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 战斗因素
 *
 * @author liyang
 * @date 2024-05-17 17:05
 */
@Getter
@Setter
public class Fight implements Serializable {

    /**
     * 生命值
     */
    private Double hp;

    /**
     * 法力值
     */
    private Double mp;

    /**
     * 攻击力
     */
    private Double attack;

    /**
     * 防御力
     */
    private Double defense;

    /**
     * 智力
     */
    private Double brain;

    /**
     * 攻击速度
     */
    private Double attackSpeed;

    /**
     * 攻击范围
     */
    private Double attackRange;

    /**
     * 速度
     */
    private Double speed;

    public Fight() {
        this.hp = 0d;
        this.mp = 0d;
        this.attack = 0d;
        this.defense = 0d;
        this.brain = 0d;
        this.attackSpeed = 0d;
        this.attackRange = 0d;
        this.speed = 0d;
    }

    public void addition(Fight addition) {
        this.hp += addition.hp;
        this.mp += addition.mp;
        this.attack += addition.attack;
        this.defense += addition.defense;
        this.brain += addition.brain;
        this.attackSpeed += addition.attackSpeed;
        this.attackRange += addition.attackRange;
        this.speed += addition.speed;
    }

    public void hpSub(Double attack) {
        synchronized (this.hashCode() + "hp") {
            this.hp -= (attack > this.defense ? attack - this.defense : 0);
            if (this.hp < 0d) {
                this.hp = 0d;
            }
        }
    }

    public void mqSub(Double d) {
        this.mp -= d;
    }

    public void attackSub(Double d) {
        this.attack -= d;
    }

    public void defenseSub(Double d) {
        this.defense -= d;
    }

    public void brainSub(Double d) {
        this.brain -= d;
    }

    public void attackSpeedSub(Double d) {
        this.attackSpeed -= d;
    }

    public void attackRangeSub(Double d) {
        this.attackRange -= d;
    }

    public void speedSub(Double d) {
        this.speed -= d;
    }

    public static Fight def() {
        Fight fight = new Fight();
        fight.hp = 100d;
        fight.mp = 20d;
        fight.attack = 1d;
        fight.defense = 1d;
        fight.brain = 1d;
        fight.attackSpeed = 1d;
        fight.attackRange = 1d;
        fight.speed = 1d;
        return fight;
    }

    public static Fight none() {
        Fight fight = new Fight();
        fight.hp = 0d;
        fight.mp = 0d;
        fight.attack = 0d;
        fight.defense = 0d;
        fight.brain = 0d;
        fight.attackSpeed = 0d;
        fight.attackRange = 0d;
        fight.speed = 0d;
        return fight;
    }
}
